package com.dengqi.mymodule.activity.camera;

import android.annotation.TargetApi;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.Toast;

import com.dengqi.mymodule.BaseActivity;
import com.dengqi.mymodule.R;
import com.dengqi.mymodule.tools.BitmapUtils;
import com.dengqi.mymodule.tools.FileUtils;
import com.dengqi.mymodule.tools.UriUtils;

import java.io.File;

/**
 * 2个问题
 * 1：三星90度
 * 2：裁剪与不裁剪图片大小不一致
 * 3：权限问题
 */
public class CameraUtilsActivity extends BaseActivity {

    private ImageView imageView;
    private PhotoUtils mPhotoUtils;
    private CheckBox checkBox;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camerautils);

        mPhotoUtils = new PhotoUtils(this);
        imageView = findViewById(R.id.imageView);
        checkBox = findViewById(R.id.checkBox);
        mPhotoUtils.setCallBackListener(new PhotoCallBack() {
            @Override
            public void callback(File targetFile) {
                Bitmap bitmap = BitmapUtils.file2Bitmap(targetFile, 1024, 1024);
                imageView.setImageBitmap(bitmap);
                //存下来只有100KB左右
//                ImageFileUtils.writeBitmap2File(bitmap, "camera.jpg");
            }
        });

    }

    public void onBtn1(View view) {
        mPhotoUtils.setIsCrop(checkBox.isChecked());
        mPhotoUtils.startCamare();
    }

    public void onBtn2(View view) {
        mPhotoUtils.setIsCrop(checkBox.isChecked());
        mPhotoUtils.startAlbum();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        mPhotoUtils.onActivityResult(requestCode, resultCode, data);
    }



}
